
# pblaze-cc 不支持中断
DOCKER_IMAGE_NAME=pb1
C_SRC=delay.c

VIR_DIR=/workspace
PATH_DOCKER=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/pblaze/bin


DOCKER_RUN=docker run -it -v $(shell pwd)/:$(VIR_DIR) -w $(VIR_DIR) -e PATH=$(PATH_DOCKER) $(DOCKER_IMAGE_NAME)

pblaze:
	@mkdir -p build
	@$(DOCKER_RUN) /bin/bash -c "cp $(VIR_DIR)/pbsoft/* /tmp -ra && cd /tmp && chown -R root:root . && mkdir -p build \
	&& pblaze-cc -march=pblaze6 -mcpu=kcpsm6 -Wall -O3 $(C_SRC) -o build/prog.elf \
	&& cp build/*   $(VIR_DIR)/build"

	@objcopy -I elf32-little -O binary -j .text  build/prog.elf  build/prog.bin

	@$(DOCKER_RUN) /bin/bash -c "cd build && pblaze-bincopy --format=mem  prog.bin  prog.mem"

	@cd build && awk -F':'	'{if(NR>3){print $$2}}' prog.mem  > prog.hex
	@echo "build/prog.hex"

udp_prog:
	@fchai.exe ./tools/upload_pblaze.chai 



pblaze_sim:pblaze
	@mkdir -p build 
	@cp build/prog.hex build/firmware.hex 
	@iverilog  -o build/tb.vvp   -I./rtl/ ./rtl/tb.v 
	@cd build && vvp tb.vvp
